//
//  DHPhoneBoundController.m
//  精品酒店
//
//  Created by DIANGHONG on 2018/5/16.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "DHPhoneBoundController.h"

@interface DHPhoneBoundController ()
@property (weak, nonatomic) IBOutlet UITextField *moblieNumTxt;
@property (weak, nonatomic) IBOutlet UITextField *confirmCodeTxt;

@end

@implementation DHPhoneBoundController
#pragma mark: - 获取验证码的按钮监听
- (IBAction)getConfirmCodeBtn:(UIButton *)sender
{
    if (!self.moblieNumTxt.hasText) {
        [SVProgressHUD showInfoWithStatus:@"请输入手机号"];
        return;
    }
    
    NSString *url = [NSString stringWithFormat:@"%@%@",REMOTEURL,@"index.php?act=member_security&op=send_modify_mobile"];
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"key"] = DHNetworkManager.shareManager.userAccount.key;
    dictM[@"mobile"] = self.moblieNumTxt.text;
    
    [DHNetworkManager.shareManager requestWithMethod:MethodGet
                                           UrlString:url params:dictM.copy
                                          completion:^(id json, BOOL isSuccess)
     {
         if (!isSuccess) {
             [SVProgressHUD showInfoWithStatus:@"请检查网络"];
             return ;
         }
         if (json[@"datas"][@"error"]) {
             [SVProgressHUD showErrorWithStatus:json[@"datas"][@"error"]];
             return;
         }
         if ([json[@"datas"][@"state"] boolValue]) {
             [SVProgressHUD showSuccessWithStatus:json[@"datas"][@"msg"]];
             return;
         }
        
     }];
}
#pragma mark: - 立即绑定 按钮监听
- (IBAction)bindMobileBtn:(id)sender
{
    if (!self.moblieNumTxt.hasText) {
        [SVProgressHUD showInfoWithStatus:@"请输入手机号"];
        return;
    }
    if (!self.confirmCodeTxt.hasText) {
        [SVProgressHUD showInfoWithStatus:@"请输入短信验证码"];
        return;
    }
    
    NSString *url = [NSString stringWithFormat:@"%@%@",REMOTEURL,@"index.php?act=member_security&op=modify_mobile"];
    NSMutableDictionary *dictM = [NSMutableDictionary dictionary];
    dictM[@"key"] = DHNetworkManager.shareManager.userAccount.key;
    dictM[@"mobile"] = self.moblieNumTxt.text;
    dictM[@"vcode"] = self.confirmCodeTxt.text;
    
    [DHNetworkManager.shareManager requestWithMethod:MethodPost UrlString:url
                                              params:dictM.copy
                                          completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            [SVProgressHUD showInfoWithStatus:@"请检查网络"];
            return ;
        }
        
        if (json[@"datas"][@"erro"]) {
            [SVProgressHUD showInfoWithStatus:json[@"datas"][@"erro"]];
            return ;
        }
        if ([json[@"datas"] boolValue]) {
            [SVProgressHUD showInfoWithStatus:@"成功"];
            [self.navigationController popToViewController:self.navigationController.childViewControllers[1] animated:true];
            return ;
        }
    }];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.tableFooterView = [[UIView alloc] init];
}

@end
